package main.java.indi.zyj.sword;

public class SockCollocation {

    public int[] sockCollocation(int[] sockets) {

        int res = sockets[0];

        for (int i = 1; i < sockets.length; i++) {
            res = res ^ sockets[i];
        }

        int m = 1;
        while ( (m & res) == 0) {
            m <<= 1;
        }

        int x = 0, y = 0;

        for (int i = 0; i < sockets.length; i++) {
            if ((m & sockets[i]) == 0) {
                x ^= sockets[i];
            } else {
                y ^= sockets[i];
            }
        }

        return new int[]{x, y};

    }

}
